{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import os\n",
    "from PIL import Image\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "data": {
      "text/plain": "['346_wallhaven-57g897.jpg',\n '346_wallhaven-dp66vg.jpg',\n '346_wallhaven-dp6vkm.jpg',\n '346_wallhaven-e78yow.jpg',\n '346_wallhaven-g8r9m3.jpg',\n '346_wallhaven-j52wmy.jpg',\n '346_wallhaven-j5gvxq.jpg',\n '346_wallhaven-lml7my.jpg',\n '346_wallhaven-md8dmm.jpg',\n '346_wallhaven-p8r5kp.jpg',\n '346_wallhaven-q67my5.jpg',\n '346_wallhaven-r2lq2q.jpg',\n '346_wallhaven-wy9wl6.jpg',\n '347_wallhaven-5wxrv1.jpg',\n '347_wallhaven-6oljow.jpg',\n '347_wallhaven-8321po.jpg',\n '347_wallhaven-963xdw.jpg',\n '347_wallhaven-eymqwl.png',\n '347_wallhaven-g836pq.png',\n '347_wallhaven-g8yez3.jpg',\n '347_wallhaven-lm6gy2.jpg',\n '347_wallhaven-lml9lr.jpg',\n '347_wallhaven-o3dovp.jpg',\n '347_wallhaven-r2vx7m.jpg',\n '347_wallhaven-x8lpxv.jpg',\n '347_wallhaven-y8mlo7.jpg',\n '347_wallhaven-y8q9ox.jpg',\n '348_wallhaven-137861.jpg',\n '348_wallhaven-39md16.jpg',\n '348_wallhaven-57l5o7.jpg',\n '348_wallhaven-5we2v3.jpg',\n '348_wallhaven-73dvpe.png',\n '348_wallhaven-73dwpy.jpg',\n '348_wallhaven-9m5lpk.jpg',\n '348_wallhaven-dp5gdl.jpg',\n '348_wallhaven-j35qkp.jpg',\n '348_wallhaven-j39elw.jpg',\n '348_wallhaven-k77e9m.jpg',\n '348_wallhaven-kwowom.jpg',\n '348_wallhaven-l38jgq.jpg',\n '348_wallhaven-oxo1e5.png',\n '348_wallhaven-q67vkl.jpg',\n '348_wallhaven-rd71k1.jpg',\n '349_wallhaven-28ej7g.jpg',\n '349_wallhaven-3zlddd.jpg',\n '349_wallhaven-6k9pk6.jpg',\n '349_wallhaven-6kvzw6.jpg',\n '349_wallhaven-8o3v1k.jpg',\n '349_wallhaven-8oge7k.jpg',\n '349_wallhaven-g7jdqe.jpg',\n '349_wallhaven-g8y7rd.jpg',\n '349_wallhaven-j3xgyp.jpg',\n '349_wallhaven-m9qvy8.jpg',\n '349_wallhaven-q67lw7.png',\n '349_wallhaven-x88j23.jpg',\n '349_wallhaven-ymd1x7.jpg',\n '349_wallhaven-ymzr2l.jpg',\n '350_wallhaven-1372g1.jpg',\n '350_wallhaven-9m63ed.jpg',\n '350_wallhaven-9md3vk.jpg',\n '350_wallhaven-dpxxwl.jpg',\n '350_wallhaven-eyj2mw.png',\n '350_wallhaven-j52zvy.png',\n '350_wallhaven-mdky1k.jpg',\n '350_wallhaven-oxk2pl.jpg',\n '350_wallhaven-pko8om.jpg',\n '350_wallhaven-q26odd.jpg',\n '350_wallhaven-r2vm8j.png',\n '350_wallhaven-x8l7yo.png',\n '350_wallhaven-xlrv2o.jpg',\n '351_wallhaven-2e7mrx.jpg',\n '351_wallhaven-6k9y97.jpg',\n '351_wallhaven-96llxk.jpg',\n '351_wallhaven-9m6jlk.jpg',\n '351_wallhaven-9mzmd1.jpg',\n '351_wallhaven-g83zmq.jpg',\n '351_wallhaven-k732z1.png',\n '351_wallhaven-k7wpj7.jpg',\n '351_wallhaven-l33x5q.jpg',\n '351_wallhaven-v9glo5.jpg',\n '351_wallhaven-wqoppr.jpg',\n '351_wallhaven-wypejq.jpg',\n '351_wallhaven-zme15v.jpg']"
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.listdir(\"./images/img\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [],
   "source": [
    "def test():\n",
    "    sample = \"./images/img/346_wallhaven-57g897.jpg\"\n",
    "    # 移动的最好办法就是通过重命名来改名路径\n",
    "    # os.rename(\"./images/img/346_wallhaven-57g897.jpg\", \"images/img/346_wallhaven-57g897.jpg\")\n",
    "    # print(os.stat(sample))\n",
    "    # img = Image.open(sample)\n",
    "    #\n",
    "    #\n",
    "    # print(np.array(img).shape)\n",
    "    os.listdir(\"./images\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "outputs": [],
   "source": [
    "def is_phone_img(path):\n",
    "    img = Image.open(path)\n",
    "    # 行数据和列（特征）\n",
    "    info = np.array(img).shape\n",
    "    h, w = info[0], info[1]\n",
    "    if h >= w:\n",
    "        return True\n",
    "    else:\n",
    "        return False"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "outputs": [],
   "source": [
    "path_head = \"./images/img/\"\n",
    "pc = \"./images/PC/\"\n",
    "phone = \"./images/phone/\""
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "outputs": [],
   "source": [
    "imgs = os.listdir(path_head)\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "outputs": [],
   "source": [
    "i = 0\n",
    "for img in imgs:\n",
    "    i  += 1\n",
    "    src_path = path_head + img\n",
    "    if is_phone_img(src_path):\n",
    "        os.rename(src_path, phone + img)\n",
    "    else:\n",
    "        os.rename(src_path, pc + img)\n",
    "    print(\"第{}张图片移动成功\".format(i))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "class MoveImage(path_head, pc, phone):\n",
    "    def __init__(self):\n",
    "        self.path_head = path_head\n",
    "        self.pc = pc\n",
    "        self.phone = phone\n",
    "\n",
    "    def is_phone_img(self, path):\n",
    "        img = Image.open(path)\n",
    "        # 行数据和列（特征）\n",
    "        info = np.array(img).shape\n",
    "        h, w = info[0], info[1]\n",
    "        if h >= w:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n",
    "\n",
    "    def run(self):\n",
    "        i = 0\n",
    "        imgs = os.listdir(self.path_head)\n",
    "        for img in imgs:\n",
    "            i  += 1\n",
    "            src_path = self.path_head + img\n",
    "            if is_phone_img(src_path):\n",
    "                os.rename(src_path, self.phone + img)\n",
    "            else:\n",
    "                os.rename(src_path, self.pc + img)\n",
    "            print(\"第{}张图片移动成功\".format(i))\n",
    "        print(\"所有图片移动成功！^_^\")\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}